package org.world.applicaiton.annimal.query;

import com.google.common.eventbus.Subscribe;
import org.mc.ddd.event.BaseEventHandler;
import org.mc.ddd.infrastructure.util.ObjectConverter;
import org.springframework.stereotype.Component;
import org.world.applicaiton.annimal.query.view.AnimalView;
import org.world.domain.aggregate.sheep.event.SheepCreatedEvent;
import org.world.infrastructure.dao.view.AnimalViewDao;

import javax.annotation.Resource;

@Component
public class AnimalViewEventHandler extends BaseEventHandler {
    @Resource
    private AnimalViewDao animalViewDao;

    @Subscribe
    public void handle(SheepCreatedEvent event) {
        AnimalView animalView = ObjectConverter.convert(event, AnimalView.class);

        animalViewDao.insert(animalView);
    }
}
